home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 6201 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.6 KB

  1. Path: news.connect.net!usenet
  2. From: tomw@intelligraphics.com
  3. Newsgroups: comp.lang.c++,comp.os.msdos.programmer
  4. Subject: Re: Function Pointers In C++
  5. Date: 10 Feb 1996 16:59:12 GMT
  6. Organization: Connection Technologies
  7. Message-ID: <4fiit0$oqp@dallas1.connect.net>
  8. References: <yAkGxc9nXE/T083yn@mbnet.mb.ca>
  9. Reply-To: tomw@intelligraphics.com
  10. NNTP-Posting-Host: igxtest.intelligraphics.com
  11. X-Newsreader: IBM NewsReader/2 v1.2
  12.  
  13. In <yAkGxc9nXE/T083yn@mbnet.mb.ca>, natewild@mbnet.mb.ca (Nathan T. Wild) writes:
  14. >
  15. >I have a class which contains function pointers.  The actual code for these
  16. >functions is dynamically loaded from disk at run time.  I seem to be having
  17. >troubles setting these pointers???  I have done this before in C, but I
  18. >guess C is a little more forgiving than C++ with respect to type checking.
  19. >The declaration for my class is as follows (byte is a typedef to unsigned
  20. >char):
  21.  
  22. The solution I used "fools" the compiler by using an anonymous union.  E.g.,
  23.  
  24.   union {
  25.     byte (*pfn) (void);
  26.     void (*vpfn) (void);
  27.   };
  28.  
  29.   vpfn = GetFunctionPtr (1);
  30.   Init = pfn;
  31.  
  32. Hope this helps.
  33.  
  34. +---------------------------------------------------------------------------+
  35. + Tom Wheeler                          | Member NRA, NMRA                   +
  36. + tomw@intelligraphics.com             | OS/2 user, C++ programmer          +
  37. + ------------------------------------------------------------------------- +
  38. + Use or reproduction of this document or the author's email address for    +
  39. + commercial purposes without the author's permission is prohibited.        +
  40. +---------------------------------------------------------------------------+
  41.  
  42.